/*! @file dbtreeview.h
  * @brief Definition of DbTreeView Class
  * This class subclasses QTreeView
  * It builds the TreeView of the file/files to be
  * processed on GUI Page 2.
  * @author AK
  * @date 20.06.2012
  */

#ifndef DBTREEVIEW_H
#define DBTREEVIEW_H

#include <QWidget>
#include <QTreeWidgetItem>
#include "defines.h"
#include "sqlite3.h"
#include "sqlitedb.h"


/*! @brief Definition of DbTreeView Class
  *
  * This class subclasses QTreeWidget
  * It builds the TreeViews of the file/files to be
  * processed in the Gui.
  * TODO: Class called View but inherited from Widget
  */
class DbTreeView : public QTreeWidget
{
    Q_OBJECT

public:
    DbTreeView(QWidget *parent = 0);
    ~DbTreeView();

    DbDetails       dbdetails;                            // struct: detailsName, detailsId

Q_SIGNALS:
    void            dbChanged(QTreeWidgetItem*, int);     // sent if dbfile changed
    void            logMe(Qt::GlobalColor, const QString);

public Q_SLOTS:
    void            addFile(int,                          // fileid
                            SqliteDb *tmpdb,              // Database Object
                            int);                         // number of all files to add
    void            clearTree();
    QList<QString>  getCheckedItemNames();                // returns checked fields
    DbDetails       getDetailsOfItem(QTreeWidgetItem*);   // returns Name and intId in struct
    QString         getSelectedFileName();
    int             getSelectedId();                      // returns id of selected file
    QList<QStringList> getSettings();                     // returns list of tables with list of checked items
    QString         getTable();                           // returns expanded table
    void            setCheckedItems(QString, QList<QString>);   // table, fields
    void            setSelected(QTreeWidgetItem*, int);

private:
    QString         filename;
    Qt::ItemFlags   flags;
    int             ft;
    int             itemcount;                              // current file number
    QString         longpath;
    int             maxcount;                               // max number of files in view
    QList<QString>  tables;
private Q_SLOTS:
    void            _foldAll();                             // unexpands all topLevelItems
    void            _log(Qt::GlobalColor, const QString &); // emits logMe
    void            _on_itemClickedOrChanged(QTreeWidgetItem*, int); // select parent to avoid force close
    void            _on_resetItemCount();                   // set itemcount to 0
    int             _setChecked(QTreeWidgetItem *, int);    // checks items according to template
    int             _toggleFolded(QTreeWidgetItem *, int);  // expands active dbfile in treeView
};

#endif // DBTREEVIEW_H
